<?php

declare(strict_types=1);

namespace Imi\Test\Component\Tool;

use Imi\Cli\Annotation\Argument;
use Imi\Cli\Annotation\Command;
use Imi\Cli\Annotation\CommandAction;
use Imi\Cli\Annotation\Option;
use Imi\Cli\Contract\BaseCommand;

use function Imi\dump;

#[Command(name: 'TestTool')]
class TestTool extends BaseCommand
{
    /**
     * 测试.
     */
    #[CommandAction(name: 'test')]
    #[Option(name: 'code', type: \Imi\Cli\ArgType::INT, default: 0)]
    public function test(int $code): void
    {
        var_dump($code);
        exit($code);
    }

    #[CommandAction(name: 'testBool', dynamicOptions: true)]
    #[Option(name: 'a1', shortcut: 'a', type: \Imi\Cli\ArgType::BOOLEAN, default: true, to: 'x')]
    #[Option(name: 'b2', shortcut: 'b', type: \Imi\Cli\ArgType::BOOLEAN, default: false, to: 'y')]
    public function testBool(bool $a1, bool $b2, bool $x, bool $y): void
    {
        var_dump($a1, $x);
        var_dump($this->input->getOption('a1'));
        var_dump($b2, $y);
        var_dump($this->input->getOption('b2'));
    }

    #[CommandAction(name: 'testArgument', dynamicOptions: true)]
    #[Argument(name: 'content', type: \Imi\Cli\ArgType::STRING, default: '', to: 'content2')]
    public function testArgument(string $content, string $content2): void
    {
        var_dump($content, $content2);
        var_dump($this->input->getArgument('content'));
    }

    #[CommandAction(name: 'testNegatable')]
    #[Option(name: 'test', shortcut: 't', type: \Imi\Cli\ArgType::BOOLEAN_NEGATABLE, default: false)]
    public function testNegatable(bool $test): void
    {
        var_dump($test);
        var_dump($this->input->getOption('test'));
    }

    #[CommandAction(name: 'testDump')]
    public function testDump(): void
    {
        dump('Hello imi!');
    }
}
